home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / CALCDATE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-14  |  3KB  |  68 lines

  1. {->>>>CalcDate<<<<---------------------------------------------}
  2. {                                                              }
  3. { Filename: CALCDATE.SRC -- Last Modified 7/11/88              }
  4. {                                                              }
  5. { This routine fills in the DateString, LongDateString, and    }
  6. { DateComp fields of the DateRec record passed to it.  It      }
  7. { requires that the Year, Month, and Day fields be valid on    }
  8. { entry.  It also requires prior definition of types DateRec   }
  9. { and String80.  DateString is formatted this way:             }
  10. {                                                              }
  11. {     Wednesday, July 17, 1986                                 }
  12. {                                                              }
  13. { DateRec is declared this way:                                }
  14. {                                                              }
  15. {     DateRec = RECORD                                         }
  16. {                 DateComp       : Word;                       }
  17. {                 LongDateString : String80;                   }
  18. {                 DateString     : String80;                   }
  19. {                 Year,Month,Day : Integer;                    }
  20. {                 DayOfWeek      : Integer                     }
  21. {               END;                                           }
  22. {                                                              }
  23. { DayOfWeek is a code from 0-6, with 0 = Sunday.               }
  24. { DateComp is a cardinal generated by the formula:             }
  25. {                                                              }
  26. {     DateComp = (Year-1980)*512 + (Month*32) + Day            }
  27. {                                                              }
  28. { It is used for comparing two dates to determine which is     }
  29. { earlier, and is the same format used in the date stamp in    }
  30. { DOS directory entries.                                       }
  31. {                                                              }
  32. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  33. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  34. {--------------------------------------------------------------}
  35.  
  36. PROCEDURE CalcDate(VAR ThisDate : DateRec);
  37.  
  38. TYPE
  39.   String9 = String[9];
  40.  
  41. CONST
  42.   MonthTags : ARRAY [1..12] of String9 =
  43.     ('January','February','March','April','May','June','July',
  44.      'August','September','October','November','December');
  45.   DayTags   : ARRAY [0..6] OF String9 =
  46.     ('Sunday','Monday','Tuesday','Wednesday',
  47.      'Thursday','Friday','Saturday');
  48.  
  49. VAR
  50.   Temp1 : String80;
  51.  
  52. BEGIN
  53.   WITH ThisDate DO
  54.     BEGIN
  55.       DayOfWeek := DateToDayOfWeek(Year,Month,Day);
  56.       Str(Month,DateString);
  57.       Str(Day,Temp1);
  58.       DateString := DateString + '/' + Temp1;
  59.       LongDateString := DayTags[DayOfWeek] + ', ';
  60.       LongDateString := LongDateString +
  61.         MonthTags[Month] + ' ' + Temp1 + ', ';
  62.       Str(Year,Temp1);
  63.       LongDateString := LongDateString + Temp1;
  64.       DateString := DateString + '/' + Copy(Temp1,3,2);
  65.       DateComp := (Year - 1980) * 512 + (Month * 32) + Day
  66.     END
  67. END;
  68.